<template>
    <div>
        <el-card class="box-card">
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>智慧书店</el-breadcrumb-item>
                <el-breadcrumb-item>书籍列表</el-breadcrumb-item>
            </el-breadcrumb>

            <!--<div>
                <el-button @click="addBook">添加商品</el-button>
            </div>-->
            <el-table :data="bookDetailedList" border style="width: 100%;height: 100%">
                <el-table-column prop="id" label="书籍编号"></el-table-column>
                <el-table-column prop="bookName" label="书籍名称"></el-table-column>
                <el-table-column prop="author" label="书籍作者"></el-table-column>
                <el-table-column prop="bookDesc" label="书籍描述"></el-table-column>
                <el-table-column prop="publishingHouse" label="书籍出版社"></el-table-column>
                <el-table-column prop="bookPrice" label="书籍价格"></el-table-column>
                <el-table-column prop="bookInventoryLevel" label="单品库存"></el-table-column>
                <el-table-column prop="onTheShelf" label="书籍状态">
                    <template slot-scope="scope">
                        <span>{{status[scope.row.onTheShelf]}}</span>
                    </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="100">
                    <template slot-scope="scope">
                        <el-button @click="updateBook(scope.row.id)" type="text" size="small">编辑</el-button>
                        <el-button type="text" size="small" @click="updateShelf(scope.row.id, scope.row.onTheShelf)">
                            <span v-if="scope.row.onTheShelf == 0">上架</span>
                            <span v-if="scope.row.onTheShelf == 1">下架</span>
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
    </div>
</template>

<script>
    export default {
        name: "BookList",
        data(){
            return{
                bookDetailedList:[],
                status:['未上架','已上架']
            }
        },methods:{
            findAll(){
              this.$http.post('/book/findAllBookDetailed').then(res =>{
                    if (res.data.success){
                        this.bookDetailedList = res.data.result.bookDetailedList;
                    } else {
                        this.$message.error(res.data.message);
                    }
                })
            },updateBook(id){
                this.$router.push({name:'UpdateBook',params:{id:id}})
            },updateShelf(id,status){
                if(status == 0){
                    status = 1
                }else {
                    status = 0
                }
                this.$http.post('/book/delBookDetailed?bookDetailedId='+id+'&deletedStatus='+status).then(res =>{
                    if (res.data.success){
                        this.findAll()
                    } else {
                        this.$message.error(res.data.message);
                    }
                })
            }
        },mounted(){
            this.findAll()
        }
    }
</script>

<style scoped>

</style>
